package com.aqian.theme.color.happy.ui.screens.wallpaper

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun WallpaperScreen(
    modifier: Modifier = Modifier
) {
    var selectedCategory by remember { mutableStateOf("全部") }
    
    Column(
        modifier = modifier.fillMaxSize()
    ) {
        // 分类选项卡
        ScrollableTabRow(
            selectedTabIndex = wallpaperCategories.indexOf(selectedCategory),
            modifier = Modifier.fillMaxWidth()
        ) {
            wallpaperCategories.forEach { category ->
                Tab(
                    selected = selectedCategory == category,
                    onClick = { selectedCategory = category },
                    text = { Text(category) }
                )
            }
        }

        // 壁纸网格
        LazyVerticalGrid(
            columns = GridCells.Fixed(2),
            contentPadding = PaddingValues(16.dp),
            horizontalArrangement = Arrangement.spacedBy(16.dp),
            verticalArrangement = Arrangement.spacedBy(16.dp),
            modifier = Modifier.fillMaxSize()
        ) {
            items(sampleWallpapers) { wallpaper ->
                WallpaperItem(wallpaper = wallpaper)
            }
        }
    }
}

@Composable
fun WallpaperItem(wallpaper: Wallpaper) {
    Card(
        modifier = Modifier
            .fillMaxWidth()
            .aspectRatio(0.75f)
    ) {
        Box(
            modifier = Modifier.fillMaxSize(),
            contentAlignment = Alignment.BottomCenter
        ) {
            // 壁纸预览（后续添加实际图片）
            Box(
                modifier = Modifier.fillMaxSize()
            )
            
            // 壁纸信息
            Surface(
                modifier = Modifier.fillMaxWidth(),
                color = MaterialTheme.colorScheme.surface.copy(alpha = 0.7f)
            ) {
                Column(
                    modifier = Modifier.padding(8.dp)
                ) {
                    Text(
                        text = wallpaper.name,
                        style = MaterialTheme.typography.titleSmall
                    )
                    Text(
                        text = "下载: ${wallpaper.downloadCount}",
                        style = MaterialTheme.typography.bodySmall
                    )
                }
            }
        }
    }
}

// 数据模型
data class Wallpaper(
    val id: String,
    val name: String,
    val imageUrl: String,
    val thumbnailUrl: String,
    val category: String,
    val downloadCount: Int
)

// 示例数据
private val wallpaperCategories = listOf(
    "全部", "风景", "动漫", "简约", "动态", "艺术", "游戏", "明星"
)

private val sampleWallpapers = listOf(
    Wallpaper(
        id = "1",
        name = "山水风景",
        imageUrl = "",
        thumbnailUrl = "",
        category = "风景",
        downloadCount = 1000
    ),
    Wallpaper(
        id = "2",
        name = "动漫女孩",
        imageUrl = "",
        thumbnailUrl = "",
        category = "动漫",
        downloadCount = 800
    ),
    Wallpaper(
        id = "3",
        name = "简约线条",
        imageUrl = "",
        thumbnailUrl = "",
        category = "简约",
        downloadCount = 600
    ),
    Wallpaper(
        id = "4",
        name = "城市夜景",
        imageUrl = "",
        thumbnailUrl = "",
        category = "风景",
        downloadCount = 750
    )
)
